home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWSemEvt / Sources / FWAplEvt.cpp next >
Encoding:
Text File  |  1996-08-16  |  7.0 KB  |  231 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWAplEvt.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWAPLEVT_H
  11. #include "FWAplEvt.h"
  12. #endif
  13.  
  14. #ifndef FWDSCOPR_H
  15. #include "FWDscOpr.h"
  16. #endif
  17.  
  18. #ifndef FWPART_H
  19. #include "FWPart.h"
  20. #endif
  21.  
  22. #ifndef FWSCPTBL_H
  23. #include "FWScptbl.h"
  24. #endif
  25.  
  26. // ----- Macintosh Includes -----
  27.  
  28. #ifndef __ASREGISTRY__
  29. #include <ASRegistry.h>
  30. #endif
  31.  
  32. // ----- OpenDoc Includes -----
  33.  
  34. #ifndef SOM_ODAppleEvent_xh
  35. #include <ODAplEvt.xh>
  36. #endif
  37.  
  38. #ifndef SOM_ODSession_xh
  39. #include <ODSessn.xh>
  40. #endif
  41.  
  42. #ifndef SOM_ODMessageInterface_xh
  43. #include <MssgIntf.xh>
  44. #endif
  45.  
  46. #if defined(__MWERKS__) && GENERATING68K
  47. // A hack to work around a bug
  48. #pragma import list somNewObjectInstance
  49. #endif
  50.  
  51. //========================================================================================
  52. //    Runtime Information
  53. //========================================================================================
  54.  
  55. #ifdef FW_BUILD_MAC    
  56. #pragma segment fwsemevt1
  57. #endif
  58.  
  59. FW_DEFINE_AUTO(FW_CAppleEvent)
  60.  
  61. //========================================================================================
  62. // CLASS FW_CAppleEvent
  63. //========================================================================================
  64.  
  65. //----------------------------------------------------------------------------------------
  66. //    FW_CAppleEvent::FW_CAppleEvent
  67. //----------------------------------------------------------------------------------------
  68.  
  69. FW_CAppleEvent::FW_CAppleEvent() :
  70.     FW_CDesc()
  71. {
  72.     FW_END_CONSTRUCTOR
  73. }
  74.  
  75. //----------------------------------------------------------------------------------------
  76. //    FW_CAppleEvent::FW_CAppleEvent
  77. //----------------------------------------------------------------------------------------
  78.  
  79. FW_CAppleEvent::FW_CAppleEvent(ODAppleEvent* odAppleEvent) :
  80.     FW_CDesc(odAppleEvent)
  81. {
  82.     FW_END_CONSTRUCTOR
  83. }
  84.  
  85. //----------------------------------------------------------------------------------------
  86. //    FW_CAppleEvent::~FW_CAppleEvent
  87. //----------------------------------------------------------------------------------------
  88.  
  89. FW_CAppleEvent::~FW_CAppleEvent()
  90. {
  91.     FW_START_DESTRUCTOR
  92. }
  93.  
  94. //----------------------------------------------------------------------------------------
  95. //    FW_CAppleEvent::HasAttributeKey
  96. //----------------------------------------------------------------------------------------
  97.  
  98. FW_Boolean FW_CAppleEvent::HasAttributeKey(ODDescType key) const
  99. {
  100.     FW_CDesc attribute;
  101.     return (::AEGetAttributeDesc(*this, key, typeWildCard, attribute) == FW_xNoError);
  102. }
  103.  
  104. //----------------------------------------------------------------------------------------
  105. //    FW_CAppleEvent::GetAttributeByKey
  106. //----------------------------------------------------------------------------------------
  107.  
  108. void FW_CAppleEvent::GetAttributeByKey(AEKeyword key, FW_CDesc& desc, ODDescType desiredType) const
  109. {
  110.     FW_FailOnError(::AEGetAttributeDesc(*this, key, desiredType, desc));
  111. }
  112.  
  113. //----------------------------------------------------------------------------------------
  114. //    FW_CAppleEvent::HasSubject
  115. //----------------------------------------------------------------------------------------
  116.  
  117. FW_Boolean FW_CAppleEvent::HasSubject() const
  118. {
  119.     return HasAttributeKey(keySubjectAttr);
  120. }
  121.  
  122. //----------------------------------------------------------------------------------------
  123. //    FW_CAppleEvent::GetSubject
  124. //----------------------------------------------------------------------------------------
  125.  
  126. void FW_CAppleEvent::GetSubject(FW_CDesc& subjectDesc) const
  127. {
  128.     GetAttributeByKey(keySubjectAttr, subjectDesc);
  129. }
  130.  
  131. //----------------------------------------------------------------------------------------
  132. //    FW_CAppleEvent::GetEventClass
  133. //----------------------------------------------------------------------------------------
  134.  
  135. AEKeyword FW_CAppleEvent::GetEventClass() const
  136. {
  137.     AEKeyword     eventClass = typeNull;
  138.     FW_CDesc    eventClassDesc;
  139.     
  140.     GetAttributeByKey(keyEventClassAttr, eventClassDesc);
  141.     eventClassDesc >> eventClass;
  142.     
  143.     return eventClass;
  144. }
  145.  
  146. //----------------------------------------------------------------------------------------
  147. //    FW_CAppleEvent::GetEventID
  148. //----------------------------------------------------------------------------------------
  149.  
  150. AEKeyword FW_CAppleEvent::GetEventID() const
  151. {
  152.     AEKeyword     eventID = typeNull;
  153.     FW_CDesc    eventIDDesc;
  154.     
  155.     GetAttributeByKey(keyEventIDAttr, eventIDDesc);
  156.     eventIDDesc >> eventID;
  157.     
  158.     return eventID;
  159. }
  160.  
  161. //----------------------------------------------------------------------------------------
  162. //    FW_CAppleEvent::operator ODAppleEvent*
  163. //----------------------------------------------------------------------------------------
  164.  
  165. FW_CAppleEvent::operator ODAppleEvent*() const
  166. {
  167.     PrivUpdateODDescIfStale();
  168.     PrivODDescChanged();
  169.     return (ODAppleEvent*)PrivGetODDescPtr();
  170. }
  171.  
  172. //----------------------------------------------------------------------------------------
  173. //    FW_CAppleEvent::operator ODAppleEvent**
  174. //----------------------------------------------------------------------------------------
  175.  
  176. FW_CAppleEvent::operator ODAppleEvent**()
  177. {
  178.     PrivDispose();
  179.     PrivODDescChanged();
  180.     return (ODAppleEvent**)PrivGetODDescHandle();
  181. }
  182.  
  183. //----------------------------------------------------------------------------------------
  184. //    FW_CAppleEvent::PrivCreateODDesc
  185. //----------------------------------------------------------------------------------------
  186.  
  187. ODDesc* FW_CAppleEvent::PrivCreateODDesc(Environment* ev) const
  188. {
  189.     ODAppleEvent* appleEvent = new ODAppleEvent;
  190.     appleEvent->InitODAppleEvent(ev);
  191.     
  192.     return appleEvent;
  193. }
  194.  
  195. //========================================================================================
  196. //    Utility Functions
  197. //========================================================================================
  198.  
  199. //----------------------------------------------------------------------------------------
  200. //    FW_MakeSetLocalPropertyEvent : Given a local scriptable object, a property type,
  201. //    and a new value for the property, create a recordable apple event that, when execute,
  202. //    sets the specified property to the new value.
  203. //
  204. //    This method is present for illustrative purposes only. ODF 1 does not implement
  205. //    factored event handling or recordability.
  206. //----------------------------------------------------------------------------------------
  207.  
  208. short FW_MakeSetLocalPropertyEvent(Environment* ev, 
  209.                                 FW_CPart* part, 
  210.                                 FW_MScriptable* theObject,
  211.                                 ODDescType whichProperty,
  212.                                 FW_CDesc& newValue,
  213.                                 FW_CAppleEvent& setPropertyEvent)
  214. {    
  215.     FW_CDesc partAddress;
  216.     ODMessageInterface* msgInt;
  217.     short returnID;
  218.     
  219.     msgInt = part->GetSession(ev)->GetMessageInterface(ev);
  220.     
  221.     msgInt->CreatePartAddrDesc(ev, partAddress, part->GetODPart(ev));
  222.     returnID = msgInt->CreateEvent(ev, kAECoreSuite, kAESetData, partAddress, 0, setPropertyEvent);
  223.     
  224.     FW_CDesc directObject;
  225.     theObject->GetPropertySpecifier(ev, part, whichProperty, directObject);
  226.     
  227.     setPropertyEvent.PutDataByDesc(directObject, keyDirectObject);
  228.     setPropertyEvent.PutDataByDesc(newValue, keyAEData);
  229.     
  230.     return returnID;
  231. }